<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 前台父控制器
 * 
 * 前台所有控制器都需要继承这个类，不包含验证
 */

class JS_Controller extends CI_Controller{
    
    //系统参数
    public $system;
    
    public function __construct() {
        parent::__construct();
        /** 开启session */
        $this->load->library('session');
        //$this->session->sess_destroy();
        /** 开启cookie */
        $this->load->helper('cookie');
        /** 检查站点当前状态 */
        $this->load->model('system_mdl');
        $this->system = $this->system_mdl->get_one();
        /** 加载路径函数 */
        $this->load->helper('url');

        /** 判断是否登录 */
        if(empty($this->session->suser->user_id)){
            redirect(site_url('login'));
        }

        if($this->system->status == 2){
            show_error('当前站点未开启');
        }
    }

    protected function _view($str,$data=array()){
        $this->load->view('default/layout/head',$data);
        $this->load->view('default/'.$str);
        $this->load->view('default/layout/bottom');
    }

    /** 发送请求 */
    protected function get_cunt($url,$data = null){
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        if(!empty($data)){
            curl_setopt($ch,CURLOPT_POST,1);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        }
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        $output = curl_exec($ch);
        curl_close($ch);
        $jsoninfo = json_decode($output);
        return $jsoninfo;
    }

    /** 密钥生成 */
    protected function get_key(){
        $boken = 'zbz123456';
        $key = substr(md5($boken),3,18);
        return $key;
    }

    /** 邮件通知（通知管理员） */
    protected function send_admin($content){
        $this->load->library('email');

        //设置发信人email地址和名称
        $this->email->from('zbzmall@yeah.net', $this->system->title, 'dickfan@yeah.net');
        //设置邮件回复地址
        $this->email->reply_to($this->system->email, $this->system->title);
        //设置发送地址
        $this->email->to($this->system->email);

        $this->email->subject($this->system->title.'-提醒');//主题
        $this->email->message($content); //内容

        $this->email->send();
    }


    
}